<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>门诊诊断</title>
</head>
<style>
    .btn_a {
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-align: center;
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: white;
        border-radius: 10px;
        border: white;
    }
    .btn_a:hover {
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_a:active{
        transform: scale(0.9);
    }
    .btn_b {
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-align: center;
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: white;
        border-radius: 10px;
        border: white;
    }
    .btn_b:hover {
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_b:active{
        transform: scale(0.9);
    }
    .btn_c {
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-align: center;
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: white;
        border-radius: 10px;
        border: white;
    }
    .btn_c:hover {
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_c:active{
        transform: scale(0.9);
    }
    .btn_d {
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-align: center;
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: white;
        border-radius: 10px;
        border: white;
    }
    .btn_d:hover {
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_d:active{
        transform: scale(0.9);
    }
    div{
        border-radius: 3px;
        min-height: 18px;
    }
     body {
         background-color: #5b84cd;
         font-family: Arial, sans-serif;
         margin: 0px;
         padding: 0px;
     }
     .div_total {
         background:linear-gradient(to top right, #ffffff,#EAEDEEFF);
         box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.2);
         height:854px ;
         width:1473px ;
         position:absolute;
         margin-top: 20px;
         margin-left: 20px;
     }
     .div_top {  background:linear-gradient(to top right, #ffffff, rgb(234, 237, 238));box-shadow: 0px 0px 10px 0px rgb(158, 166, 166);height:106px ;position:relative; margin: 10px;}
     .div_img { height:95px ;float:none;width:147px ;position:relative;left:10px;bottom:96px;margin:5px 0 5px 0; }
     .div_main { position:relative;top:2px;height:700px ;margin:22px auto 22px auto; }
    .div_main_left {  background:linear-gradient(to top right, #ffffff, rgb(234, 237, 238));box-shadow: 0px 0px 10px 0px rgb(158, 166, 166);margin:10px 10px 10px 10px;position:relative;width:147px ;height:678px ; }
    .div_main_right {  background:linear-gradient(to top right, #ffffff, rgb(234, 237, 238));box-shadow: 0px 0px 10px 0px rgb(158, 166, 166);margin:0px 10px 10px 10px;position:absolute;left:168px;top:0px;width:1282px ;height:678px ; }
     .img { height:94px ;width:117px ;position:relative;left:14px;margin:auto auto auto auto;background-size:cover;background-attachment:local;background-origin:border-box;}

    .tittle { position:relative;color:rgba(0, 0, 0, 1);font-style:normal;font-size:27px;text-shadow:0 0 0 rgba(0, 0, 0 );box-shadow:0 0 0 0 rgba(31, 31, 31);opacity:1;transform:translate(0,19px);border:rgba(31, 31, 31, 1) solid 1px;text-align:center;letter-spacing:5px; border-radius:3px }

     .btn_b { position:relative;width:140px ;height:95px ;bottom:0px;font-style:normal;color:rgba(0, 0, 0, 1);font-size:32px;font-weight:bolder;text-align:center;text-decoration:underline;cursor:pointer; }
     .btn_c { width:140px ;height:95px ;position:relative;font-size:32px;font-style:normal;font-weight:bolder;text-align:center;text-decoration:underline;color:rgba(0, 0, 0, 1);cursor:pointer; }
     .btn_d { width:140px ;height:95px ;position:relative;color:rgba(0, 0, 0, 1);font-style:normal;font-size:32px;font-weight:bolder;text-align:center;text-decoration:underline;cursor:pointer; }
     .btn_a { width:140px ;height:95px ;position:relative;color:rgba(0, 0, 0, 1);font-size:32px;font-style:normal;font-weight:bolder;text-align:center;text-decoration:underline;cursor:pointer; }

    .form_a { position:relative;top:10px;left:10px;bottom:10px;right:10px;width:1240px ;margin:10px 10px 10px 10px;cursor:pointer;height:650px ; }
     .div_name { position:relative;margin:10px 10px 10px 10px;height:50px ; }
     .div_age { margin:10px 10px 10px 10px;position:relative;height:50px ; }
     .div_sexy { margin:10px 10px 10px 10px;position:relative;height:50px ; }
     .div_symptom { margin:10px 10px 10px 10px;position:relative;height:100px ; }
     .div_diagnose { margin:10px 10px 10px 10px;position:relative;height:100px ; }
     .div_treat { position:relative;margin:10px 10px 10px 10px;height:160px ; }
     .txt_name { margin:0 10px 10px 25px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;position:relative;top:10px; }
     .name { border:rgba(0, 0, 0, 1) solid 1px;margin:0 10px 10px 0;position:relative;height:24px ;width:300px ;font-style:italic;font-weight:normal;cursor:text;color:rgba(0, 0, 0, 1);font-size:25px;top:10px; }
     .age { border:rgba(0, 0, 0, 1) solid 1px;margin:0 10px 10px 0;width:300px ;height:24px ;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-size:25px;font-weight:normal;cursor:text;font-style:italic; }
     .txt_age { margin:0 10px 10px 25px;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer; }
     .sexy { margin:0 10px 10px 0;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;border:rgba(0, 0, 0, 1) solid 1px;font-weight:normal;cursor:pointer;height:32px ;width:60px ;text-align:center; }
     .txt_sexy { margin:0 10px 10px 25px;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;text-align:center;cursor:pointer; }
     .symptom { border:rgba(0, 0, 0, 1) solid 1px;margin:0 10px 10px 0;position:relative;top:10px;width:500px ;height:70px ;cursor:text;color:rgba(0, 0, 0, 1);font-size:20px;font-style:italic;font-weight:normal; }
     .txt_symptom { margin:0 10px 10px 25px;position:relative;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;bottom:53px; }
     .diagnosis { border:rgba(0, 0, 0, 1) solid 1px;margin:0 10px 10px 0;width:500px ;height:70px ;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-style:italic;font-size:20px;cursor:text; }
     .txt_diagnosis { margin:0 10px 10px 25px;position:relative;bottom:53px;font-style:normal;color:rgba(0, 0, 0, 1);font-size:25px;font-weight:bolder;cursor:pointer; }
     .treat { margin:0 auto 10px 0;position:relative;top:10px;border:rgba(0, 0, 0, 1) solid 1px;height:150px ;color:rgba(0, 0, 0, 1);font-style:italic;font-size:20px;cursor:text;font-weight:normal;width:850px ; }
     .txt_treat { margin:0 10px 10px 25px;position:relative;bottom:134px;font-size:25px;color:rgba(0, 0, 0, 1);font-weight:bolder;cursor:pointer; }

     .btn_print  {
         top:15px;
         left:780px;
         font-size:18px;
         position:relative;
         border: solid 1px black;
         background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
         text-transform: uppercase;
         transition: 0.5s;
         background-size: 200% auto;
         color: #000000;
         border-radius: 3px;
         border: black;
         cursor: pointer;
     }
     .btn_print:hover{
         background-position: right center; /* change the direction of the change here */
         color: #fff;
         text-decoration: none;
     }
     .btn_print:active{
         transform: scale(0.9);
     }
    .btn_create  {
        top:15px;
        left:780px;
        font-size:18px;
        position:relative;
        border: solid 1px black;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
        cursor: pointer;
    }
    .btn_create:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_create:active{
        transform: scale(0.9);
    }
    .btn_delete  {
        top:15px;
        left:780px;
        font-size:18px;
        position:relative;
        border: solid 1px black;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
        cursor: pointer;
    }
    .btn_delete:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_delete:active{
        transform: scale(0.9);
    }
    .btn_save  {
        top:15px;
        left:780px;
        font-size:18px;
        position:relative;
        border: solid 1px black;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
        cursor: pointer;
    }
    .btn_save:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_save:active{
        transform: scale(0.9);
    }

     .div_btn { position:relative;left:179px;top:5px;margin:5px 0 0 5px;height:95px ;width:1270px ; }
     .div_user { float:right;position:relative;margin:10px 10px 10px 10px;width:414px ;height:70px ;top:2px;cursor:pointer; }
    .user {
        color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;text-align:center;cursor:pointer;position:relative;top:20px;
    }
    a{
        color:rgba(0, 0, 0, 1);font-style:normal;font-size:15px;text-align:center;cursor:pointer;position:relative;top:20px;left: 10px;
    }
    .patient_list{
        position: relative;
        overflow-y: auto;
        height: 462px;
    }
    .patient_list div{
        text-align: center;
        font-size: 20px;
    }
    #search_name{
        width: 130px;
        border: solid 1px black;
        border-radius: 3px;
    }
    ul li{
        list-style-type: none;
        font-size: 20px;
    }
    #search_name_btn{
        position: absolute;
        width: 148px;
        border: solid 1px black;
        font-size: 15px;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
    }
    #search_name_btn:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
        border: solid 1px black;
    }
    #search_name_btn:active{
        transform: scale(0.9);
    }
    input {
        font-size:12px;font-family: 'Microsoft YaHei', '微软雅黑', MicrosoftJhengHei, '华文细黑', STHeiti, MingLiu;
        border:rgb(235, 235, 235) 1px solid;border-radius: 3px;padding: 5px 8px;outline: 0;
    }
    input:hover{ border: 1px solid #020202; }
    .whether_diagnosis_done{
        position: absolute;
        display: flex;

        width: 147px;
    }
    .whether-diagnostic{
        flex: 1;
        border: solid 1px;
        font-size: 15px;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
    }
    .whether-diagnostic:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
        border: solid 1px black;
    }
    .whether-diagnostic:active{
        transform: scale(0.9);
    }
    .ul_patients{
        position: relative;
        top: 30px;
    }
    #xmlParseForm{
        position: absolute;
        top: 15px;
    }
    #xml_upload{
        position: absolute;
        left: 600px;
        height:90px;
        width: 240px;
    }
    .upload_btn{
        
        height: 30px;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        border: none;
        border-radius: 3px;
    }
</style>
<link href="/static/script/bootstrap_3.3.0/css/modal.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="https://www.58html.com/gui/css/font-awesome/css/font-awesome.css">
<div class="modal fade" id="createMedicalRecordModal" role="dialog">
    <div class="modal-dialog" role="document" style="width: 50%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h2 class="modal-title" id="myModalLabel1">新建病历</h2>
            </div>
            <div class="modal-body">

                <form id="createMedicalRecordForm" class="form-horizontal" role="form">

                    <div class="form-group">
                        <label for="create-doctorName" class="col-sm-2 control-label">医生姓名</label>
                        <div class="col-sm-10" style="width: 150px;">
                            <input type="text" class="form-control" id="create-doctorName" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="create-patientName" class="col-sm-2 control-label">病人姓名</label>
                        <div class="col-sm-10" style="width: 150px;">
                            <input type="text" class="form-control" id="create-patientName" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="create-sexy" class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-10" style="width: 150px;">
                            <input type="text" class="form-control" id="create-sexy" readonly>
                        </div>
                    </div>
                    <div id="core_content">
                        <div class="form-group">
                            <label for="create-symptom" class="col-sm-2 control-label">症状<span style="font-size: 15px; color: red;">*</span></label>
                            <div class="col-sm-10" style="width: 267%;">
                                <textarea class="form-control" rows="3" id="create-symptom"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="create-diagnosis" class="col-sm-2 control-label">诊断<span style="font-size: 15px; color: red;">*</span></label>
                            <div class="col-sm-10" style="width: 267%;">
                                <textarea class="form-control" rows="3" id="create-diagnosis"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="create-treat" class="col-sm-2 control-label">治疗<span style="font-size: 15px; color: red;">*</span></label>
                            <div class="col-sm-10" style="width: 267%;">
                                <textarea class="form-control" rows="3" id="create-treat"></textarea>
                            </div>
                        </div>
                    </div>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="saveMedicalRecordBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<div id="lyrow">
    <div class="div_total">
        <div class="div_top">
            <div class="div_btn">
                <div id="xml_upload">
                    <form action="/xmlParse/upload" enctype="multipart/form-data" method="post" id="xmlParseForm">
                        <input type="file" name="file" id="file" style="position: absolute;opacity: 0;left: 0px;top: 0px;">
                        <button class="upload_btn">上传文件</button>
                        <input type="submit"  value="提交" style="position: relative;left: 20px;background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);border: none;border-radius: 3px;"><br>
                    </form>
                    <button type="button" onclick="downloadFile()" class="upload_btn" style="position: relative;top: 50px">下载文件</button>
                </div>
                <div class="div_user">
                    <span class="user" th:text="${doctor.getDoctorName()}">王忠</span>
                    <a href="/changePassword">修改密码</a>
                    <a href="/logout">退出登录</a>
                    <a href="/changeAccount">更改账户</a>
                </div>

                <input type="button" name="button" value="门诊诊断" class="btn_a">
                <input type="button" name="button" value="门诊处方" class="btn_b">
                <input type="button" name="button" value="申请单" class="btn_c">
                <input type="button" name="button" value="门诊历史" class="btn_d">
            </div>
            <div class="div_img">
                <img src="http://localhost:8080/static/img/图标.png" class="img">
            </div>
        </div>
        <div class="div_main">
            <div class="div_main_left">
                <h1 class="tittle">病人列表</h1>
                <div class="patient_list">
                    <div class="whether_diagnosis_done">
                        <input type="button" class="whether-diagnostic" id="diagnosis_done" value="已诊">
                        <input type="button" class="whether-diagnostic" id="no_diagnosis_done" value="未诊">
                    </div>
                    <ul class="ul_patients">
                    </ul>
                </div>
                <input type="text" name="search_name" id="search_name" value="">
                <input type="button" id="search_name_btn" value="查询"/>
            </div>
            <div class="div_main_right">
                <div class="form_a">
                    <div class="div_name">
                        <span class="txt_name">姓名:</span>
                        <input type="text" name="input" class="name" placeholder="请输入姓名" value="" readonly></div>
                    <div class="div_age">
                        <span class="txt_age">年龄:</span>
                        <input type="text" name="input" class="age" value="" placeholder="请输入年龄" readonly></div>
                    <div class="div_sexy">
                        <span class="txt_sexy">性别:</span>
                        <select name="select" class="sexy">
                            <option value="1" >男</option>
                            <option value="0" >女</option>
                        </select> </div>
                    <div class="div_symptom">
                        <span class="txt_symptom">症状:</span>
                        <textarea name="textarea" class="symptom" placeholder="请输入症状"></textarea></div>
                    <div class="div_diagnose">
                        <span class="txt_diagnosis">诊断:</span>
                        <textarea name="textarea" class="diagnosis" placeholder="请输入诊断"></textarea></div>
                    <div class="div_treat">
                        <span class="txt_treat">治疗:</span>
                        <textarea name="textarea" class="treat" placeholder="请输入治疗方案"></textarea></div>
                    <input type="button" name="button" value="打印" class="btn_print">
                    <input type="button" name="button" value="删除" class="btn_delete">
                    <input type="button" name="button" value="保存" class="btn_save">
                    <input type="button" name="button" value="新建" class="btn_create">

                </div>
            </div>
        </div>
    </div>
</div>
<div class="print-view" style="position:absolute;width:0px;height:0px;left:-500px;top:-500px;">
    <div class="container">
        <div class="header">
            <img src="/static/img/图标.png" class="img">
            <h2 style="position: absolute;top: 130px;">病人病历</h2>
            <h3 style="top: 160px;position: absolute">------------------------------------------------------------------------------------------------------------------</h3>
        </div>

        <div class="section" style="margin-top: 50px">

            <h2>患者信息</h2>
            <table class="table" id="tb_patientInformation">
                <tr>
                    <th>姓名</th>
                    <td id="td_patient_name"></td>
                </tr>
                <tr>
                    <th>性别</th>
                    <td id="td_sexy"></td>
                </tr>
                <tr>
                    <th>年龄</th>
                    <td id="td_age"></td>
                </tr>

                <tr>
                    <th>就诊日期</th>
                    <td id="td_date"></td>
                </tr>
                <tr>
                    <th>医生</th>
                    <td id="td_doctor_name"></td>
                </tr>
                <tr>
                    <th>科室</th>
                    <td id="td_department"></td>
                </tr>
            </table>
        </div>
        <div class="section">
            <h2>病历信息</h2>
            <table class="table" id="tb_medicalInformation">
                <tr>
                    <th>症状</th>
                    <td id="td_symptoms"></td>
                </tr>
                <tr>
                    <th>诊断</th>
                    <td id="td_diagnosis"></td>
                </tr>
                <tr>
                    <th>治疗</th>
                    <td id="td_treat"></td>
                </tr>
            </table>
        </div>
    </div>
    <footer style="text-align: center;position: relative;top: 200px">
        <p>版权所有 © xdy 打印预览示例</p>
        <h3 style="position: relative">------------------------------------------------------------------------------------------------------------------</h3>
    </footer>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<script  src="/static/script/jquery-1.11.1-min.js"></script>
<script  src="/static/script/bootstrap_3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
            $(function (){
                $(".btn_a").css({color:"#f1f1f1"})
                $(".btn_b").css({color:"#000000"})
                $(".btn_c").css({color:"#000000"})
                $(".btn_d").css({color:"#000000"})
            })
            var patient_id="";
            var medical_record_id="";
            //状态变量，来判断textarea发生改变后是否保存
            var flag=true;
            $("textarea").change(function (){
                flag=false;
            })
            /**
             * 状态变量，在查询病人时判断当前处于是否完成诊断的列表下 false:处于为诊断; true:处于已经诊断下
             * @type {boolean}
             */
            var whether_diagnosis_flag=true;
            //加载已经诊断病人列表
            function list_diagnosis_done_patients(){
                $.ajax({
                    url:'/main/diagnosis_done_patient_list',
                    type:'post',
                    dataType:'json',
                    success:function (data){
                        var html="";
                        $.each(data.patients,function (index,obj){
                            html+="<li value=\""+obj.patientId+"\"onclick='getPatientMedicalRecord($(this))'>"+obj.patientName+"</li>"
                        });
                        $(".ul_patients").html(html);
                    }
                })
            }
            //加载未诊断病人列表
            function list_no_diagnosis_done_patients(){
                $.ajax({
                    url:'/main/no_diagnosis_done_patient_list',
                    type:'post',
                    dataType:'json',
                    success:function (data){
                        var html="";
                        $.each(data.patients,function (index,obj){
                            html+="<li value=\""+obj.patientId+"\"onclick='getPatientMedicalRecord($(this))'>"+obj.patientName+"</li>"
                        });
                        $(".ul_patients").html(html);
                    }
                })
            }
            //给未诊添加单击事件
            $("#no_diagnosis_done").click(function (){
                whether_diagnosis_flag=false;
                list_no_diagnosis_done_patients();
            })
            //给已诊添加单击事件
            $("#diagnosis_done").click(function (){
                whether_diagnosis_flag=true;
                list_diagnosis_done_patients();
            })
            //给门诊诊断按钮添加单击事件
            $(".btn_a").click(function (){
                window.location.href="/main/index";
            })
            //门诊处方按钮
            $(".btn_b").click(function (){
                window.location.href="/prescription/index";
            })

            //给申请单添加单击事件
            $(".btn_c").click(function (){
                window.location.href="/applicationForm/index";
            })
            //给门诊历史添加单击事件
            $(".btn_d").click(function (){
                window.location.href="/history/index";
            })
            //单击病人显示病历信息
            function getPatientMedicalRecord(obj){
                    patient_id=$(obj).val();
                    $("li").css({background: "#f1f1f1"});
                    $(obj).css({background: "#a3a8b6",width:"60px",borderRadius:"5px"})
                    $.ajax({
                        url:'/main/patient_medical_record',
                        data:{
                            patient_id:patient_id,
                        },
                        type: 'post',
                        dataType: 'json',
                        success:function (data){
                            $(".name").val(data.patient.patientName);
                            $(".age").val(data.patient.patientAge);
                            if(data.patient.patientSex=="男"){
                                $(".sexy option[value='1']").attr("selected",true);
                                $(".sexy option[value='0']").removeAttr("selected");
                            }else{
                                $(".sexy option[value='0']").attr("selected",true);
                                $(".sexy option[value='1']").removeAttr("selected");
                            }
                            $(".symptom").val(data.symptom);
                            $(".diagnosis").val(data.diagnosis);
                            $(".treat").val(data.treatmentOptions);
                            medical_record_id=data.medicalRecordId;
                        }
                    })
            }
            //给查询按钮添加单击事件
            $("#search_name_btn").click(function (){
                var search_name=$("#search_name").val();
                $.ajax({
                    url:'/main/queryBySearchName',
                    data:{
                        search_name:search_name,
                        whether_diagnosis_flag:whether_diagnosis_flag
                    },
                    dataType:'json',
                    type:'post',
                    success:function (data){
                        var html="";
                        $.each(data.patients,function (index,obj){
                            html+="<li value=\""+obj.patientId+"\"onclick='getPatientMedicalRecord($(this))'>"+obj.patientName+"</li>"
                        });
                        $(".ul_patients").html(html);
                    }
                })
            })
            //查询框enter事件
            $("#search_name").keyup(function (event){
                if(event.keyCode===13){
                    $("#search_name_btn").trigger("click");
                }
            })
            //给保存按钮添加单击事件
            $(".btn_save").click(function (){
                if(patient_id==""){
                    alert("请选择病人");
                }else{
                    flag=true;
                    var name=$(".name").val()
                    var age=$(".age").val()
                    var sexy=$(".sexy-").val()
                    var symptom=$(".symptom").val();
                    var diagnosis=$(".diagnosis").val();
                    var treat=$(".treat").val();
                    if(name==""||age==""||sexy==""||symptom==""||diagnosis==""||treat==""){
                        alert("请完善病历信息")
                    }else{
                        $.ajax({
                            url:'/main/saveAndUpdateMedicalRecord',
                            data:{
                                patient_id:patient_id,
                                symptom:symptom,
                                diagnosis:diagnosis,
                                treat,treat,
                                medical_record_id:medical_record_id
                            },
                            type:'post',
                            dataType:'json',
                            success:function (data){
                                if(data.code=='1'){
                                    alert(data.message);
                                }else{
                                    alert(data.message)
                                }
                            }
                        })
                    }
                }

            })
            //给"新建"按钮添加单击事件
            $(".btn_create").click(function () {
                if(patient_id==""){
                    alert("请选择病人");
                }else{
                    var patient_name=$(".name").val();
                    var doctor_name=$(".user").text();
                    var patient_sexy=$(".sexy").val();
                    //初始化工作
                    //重置表单
                    $("#createMedicalRecordForm").get(0).reset();
                    //弹出新建病历的模态窗口
                    $("#createMedicalRecordModal").modal("show");
                    $("#create-doctorName").val(doctor_name);
                    $("#create-patientName").val(patient_name);
                    if(patient_sexy=="1"){
                        $("#create-sexy").val("男");
                    }else{
                        $("#create-sexy").val("女");
                    }
                }
            });
            //给新建保存添加单击事件
            $("#saveMedicalRecordBtn").click(function (){
                var symptom=$("#create-symptom").val();
                var diagnosis=$("#create-diagnosis").val();
                var treat=$("#create-treat").val();
                if(symptom==""||diagnosis==""||treat==""){
                    alert("请完善病历");
                }else{
                    $.ajax({
                        url:'/main/createMedicalRecord',
                        data:{
                            patient_id:patient_id,
                            symptom:symptom,
                            diagnosis:diagnosis,
                            treat,treat
                        },
                        type:'post',
                        dataType:'json',
                        success:function (data){
                            if(data.code=="0"){
                                alert("新建失败")
                            }else{
                                list_no_diagnosis_done_patients();
                                $("#createMedicalRecordModal").modal("hide");
                                $(".symptom").val(data.symptom);
                                $(".diagnosis").val(data.diagnosis);
                                $(".treat").val(data.treat);
                                medical_record_id=data.medicalRecordId;
                                console.log(medical_record_id);
                            }
                        }
                    })
                }
            })
            //给删除按钮添加单击事件
            $(".btn_delete").click(function (){
                if(patient_id==""){
                    alert("请选择病人");
                }else{
                    $.ajax({
                        url:'/main/delete',
                        data:{
                            patient_id:patient_id
                        },
                        type:'post',
                        dataType:'json',
                        success:function (data){
                            if(data.code==1){
                                alert(data.message);
                                window.location.href="/main/index";
                            }else{
                                alert(data.message);
                            }
                        }
                    })
                }
            })
            //给打印添加单击事件
            $(".btn_print").click(function (){
                if(patient_id==""){
                    alert("请选择病人");
                }else if(flag){
                    $.ajax({
                        url:'/main/print',
                        data:{
                            patient_id:patient_id
                        },
                        type:'post',
                        dataType:'json',
                        success:function (data){
                            if(data.code==0){
                                alert(data.msg);
                            }else{
                                $(".print-preview").text("");
                                $("#td_patient_name").text(data.patientName);
                                $("#td_age").text(data.patientAge);
                                $("#td_sexy").text(data.patientSexy);
                                $("#td_date").text(data.date);
                                $("#td_doctor_name").text(data.doctorName);
                                $("#td_department").text(data.department);
                                $("#td_symptoms").text(data.symptom);
                                $("#td_diagnosis").text(data.diagnosis);
                                $("#td_treat").text(data.treat);

                                var iframe=document.getElementById("print-iframe");
                                if(iframe==null){
                                    var html=$(".print-view").html();
                                    iframe = document.createElement('IFRAME');
                                    var doc = null;
                                    iframe.setAttribute("id", "print-iframe");
                                    iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
                                    document.body.appendChild(iframe);
                                    doc=iframe.contentWindow.document;
                                    doc.write("<link href=\"/static/script/bootstrap_3.3.0/css/print_preview.css\" type=\"text/css\" rel=\"stylesheet\" />")
                                    doc.write("<div>"+html+"</div>")
                                    doc.close();
                                    iframe.contentWindow.focus();
                                }
                                setTimeout(function(){ iframe.contentWindow.print();},50)
                                setTimeout(()=>{
                                    document.body.removeChild(iframe);
                                },2000);
                            }
                        }
                    })
                }else{
                    alert("当前病历为保存，请先保存")
                }
            })
            
            
            function downloadFile() {
                fetch('/xmlParse/download', {
                    method: 'GET',
                    credentials: 'same-origin',
                    headers: {
                        'Content-Type': 'application/json'
                    }
                })
                        .then(response => response.blob())
                        .then(blob => {
                            saveAs(blob, "patientInfoDtos.xml");
                        })
                        .catch(error => {
                            console.error('发生了错误', error);
                        });
            }
</script>
</html>